package org.ss.psci.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.ss.psci.entity.PmCost;

/**
 * Data access object (DAO) for domain model class PmCost.
 * 
 * @see org.ss.psci.entity.PmCost
 * @author MyEclipse Persistence Tools
 */

public class PmCostDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(PmCostDAO.class);
	// property constants
	public static final String COST_SEQ = "costSeq";
	public static final String MANAGER = "manager";
	public static final String CT_TIME = "ctTime";
	public static final String TYPE = "type";
	public static final String COST_NAME = "costName";
	public static final String ASS_ID = "assId";
	public static final String COST = "cost";
	public static final String PER_PRICE = "perPrice";
	public static final String NUM = "num";
	public static final String REMARK = "remark";
	public static final String TOTAL_PRICE = "totalPrice";
	public static final String PROJECTID = "projectId";

	public List findByProject(Object name) {
		return findByProperty(PROJECTID, name);
	}
	
	protected void initDao() {
		// do nothing
	}

	public void save(PmCost transientInstance) {
		log.debug("saving PmCost instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(PmCost persistentInstance) {
		log.debug("deleting PmCost instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public PmCost findById(java.lang.Integer id) {
		log.debug("getting PmCost instance with id: " + id);
		try {
			PmCost instance = (PmCost) getHibernateTemplate().get(
					"org.ss.psci.entity.PmCost", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(PmCost instance) {
		log.debug("finding PmCost instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding PmCost instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from PmCost as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCostSeq(Object costSeq) {
		return findByProperty(COST_SEQ, costSeq);
	}

	public List findByManager(Object manager) {
		return findByProperty(MANAGER, manager);
	}

	public List findByCtTime(Object ctTime) {
		return findByProperty(CT_TIME, ctTime);
	}

	public List findByType(Object type) {
		return findByProperty(TYPE, type);
	}

	public List findByCostName(Object costName) {
		return findByProperty(COST_NAME, costName);
	}

	public List findByAssId(Object assId) {
		return findByProperty(ASS_ID, assId);
	}

	public List findByCost(Object cost) {
		return findByProperty(COST, cost);
	}

	public List findByPerPrice(Object perPrice) {
		return findByProperty(PER_PRICE, perPrice);
	}

	public List findByNum(Object num) {
		return findByProperty(NUM, num);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findByTotalPrice(Object totalPrice) {
		return findByProperty(TOTAL_PRICE, totalPrice);
	}

	public List findAll() {
		log.debug("finding all PmCost instances");
		try {
			String queryString = "from PmCost";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public PmCost merge(PmCost detachedInstance) {
		log.debug("merging PmCost instance");
		try {
			PmCost result = (PmCost) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(PmCost instance) {
		log.debug("attaching dirty PmCost instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(PmCost instance) {
		log.debug("attaching clean PmCost instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static PmCostDAO getFromApplicationContext(ApplicationContext ctx) {
		return (PmCostDAO) ctx.getBean("PmCostDAO");
	}
}